package com.liuwei.msmall.order.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * @Classname SessionConfig
 * @Description TODO
 * @Date 2020/6/27 1:32
 * @Created by 刘
 */
@Configuration
public class SessionConfig {


    //配置session序列化到redis中的序列化器,将数据序列化为json数据
    @Bean
    public RedisSerializer<Object> springSessionDefaultRedisSerializer() {

        return new GenericJackson2JsonRedisSerializer();
    }


    //配置cookie
    @Bean
    public CookieSerializer cookieSerializer() {
        DefaultCookieSerializer serializer = new DefaultCookieSerializer();
        serializer.setCookieName("MSMALLSESSIONID"); //设置cookie名字
        serializer.setDomainName("msmall.com"); //设置cookie作用的域名范围为父域名
        return serializer;
    }


}
